package com.mccrea.pattern.iterator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Classname BookShelf
 * @Description 书架类，存放书的集合
 * @Date 2021/5/20 0020 17:27
 * @Created by Mccrea_Gao
 */
public class BookShelf implements Aggregate {

    private List<Book> books;

    public BookShelf() {
        this.books = new ArrayList<>();
    }

    public Book getBookAt(int index) {
        return books.get(index);
    }

    public void addBook(Book book) {
        books.add(book);
    }

    public int getLength() {
        return books.size();
    }

    @Override
    public Iterator<Book> iterator() {
        return new BookShelfIterator(this);
    }
}
